﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Nizm0.QOT.Library.Generators
{
    class Regon
    {
        private int[] RegArr = new int[9];

        private void getchecksum()
        {
            int sum = RegArr[0] * 8 + RegArr[1] * 9 + RegArr[2] * 2 + RegArr[3] * 3 + RegArr[4] * 4 + RegArr[5] * 5 + RegArr[6] * 6 + RegArr[7] * 7;
            int mod11 = sum % 11;
            if (mod11 == 10)
            {
                mod11 = 0;
            }
            RegArr[8] = mod11;
        }   

        public string GetRegon()
        {
            string reg = "";
            Random rand = new Random(DateTime.Now.GetHashCode());

            for (int i = 0; i <= 7; i++)
            {
                int n = rand.Next(1, 9);
                RegArr[i] = n;
            }

            getchecksum();

            foreach (int i in RegArr)
            {
                reg = reg + i.ToString();
            }
            return reg;
        }
    }
}
